﻿----------------
-- setting up --
----------------

function callClientFunction ( funcname, ... ) 
	local arg = { ... } 
	if ( arg [ 1 ] ) then
		for key, value in next, arg do arg [ key ] = tonumber ( value ) or value end
	end
	loadstring ( "return "..funcname ) () ( unpack ( arg ) ) 
end
addEvent ( "onServerCallsClientFunction", true ) 
addEventHandler ( "onServerCallsClientFunction", resourceRoot, callClientFunction ) 

function math.round ( number )
	return tonumber ( ( "%." .. 3 .. "f" ):format ( number ) )
end

function announce ( msgType )
	if msgType == "noVeh" then
		outputChatBox ( "You have to be in a #9696ffvehicle#6464ff!", 100, 100, 255, true )
	elseif msgType == "noComp" then
		outputChatBox ( "No #9696ffcomponent #6464ffselected!", 100, 100, 255, true )
	end
end

function commaToDot ( str )
	local str = string.gsub ( str, ",", "." )
	return tonumber ( str )
end

do -- setting vars
	guiSetInputMode ( "no_binds_when_editing" )
	thePlayer = getLocalPlayer ()
	theVehicle = getPedOccupiedVehicle ( thePlayer )
	pos = 0.1
	rot = 15
	posrot = { x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0 }
	theComponent = nil
	boolToFactor = { [ false ] = 0, [ true ] = 1 }
	showBoolToColor = { [ true ] = { 255, 255, 255 }, [ false ] = { 120, 120, 255 } }
end

-- format of data
-- setElementData ( vehicle, "VCSM", table )
-- table = { componentName1, componentName2, ... }
-- componentName* = { bool visibility, float x, float y, float z, float rx, float ry, float rz }

------------------
-- creating GUI --
------------------

do -- GUI creating funcs
	g_Window = {} 
	g_Button = {}
	g_Checkbox = {}
	g_Label = {}
	g_OffsetsEdit = {} 
	g_Edit = {} 
	g_Radio = {}
	g_Grid = {} 
	
	-- main window
	g_Window [ 1 ] = guiCreateWindow ( 0.6695, 0.2279, 0.3305, 0.3971, "Vehicle Component Serverside Manager 1.0 by Yamsha", true ) 
	
	g_Button [ 1 ] = guiCreateButton ( 0.3877, 0.3344, 0.2317, 0.0951, "Apply", true, g_Window [ 1 ] ) 
	g_Button [ 2 ] = guiCreateButton ( 0.3877, 0.5607, 0.1017, 0.0721, "+", true, g_Window [ 1 ] ) 
	g_Button [ 3 ] = guiCreateButton ( 0.5177, 0.5607, 0.1017, 0.0721, "—", true, g_Window [ 1 ] ) 
	g_Button [ 4 ] = guiCreateButton ( 0.0307, 0.882, 0.1324, 0.0885, "Close", true, g_Window [ 1 ] ) 
	g_Button [ 5 ] = guiCreateButton ( 0.8298, 0.882, 0.1324, 0.0885, "Refresh", true, g_Window [ 1 ] ) 
	g_Button [ 6 ] = guiCreateButton ( 0.2339, 0.7738, 0.1797, 0.0885, "Reset All", true, g_Window [ 1 ] )
	g_Button [ 7 ] = guiCreateButton ( 0.4397, 0.7738, 0.1797, 0.0885, "Reset", true, g_Window [ 1 ] )
	g_Button [ 8 ] = guiCreateButton ( 0.2339, 0.882, 0.1797, 0.0885, "Visiblity All", true, g_Window [ 1 ] )
	g_Button [ 9 ] = guiCreateButton ( 0.4397, 0.882, 0.1797, 0.0885, "Visibility", true, g_Window [ 1 ] )
	
	g_Checkbox.x = guiCreateCheckBox ( 0.2955, 0.4721, 0.0355, 0.0459, "", true, true, g_Window [ 1 ] ) 
	g_Checkbox.y = guiCreateCheckBox ( 0.2955, 0.518, 0.0355, 0.0459, "", false, true, g_Window [ 1 ] ) 
	g_Checkbox.z = guiCreateCheckBox ( 0.2955, 0.5639, 0.0355, 0.0459, "", false, true, g_Window [ 1 ] ) 
	
	g_Label [ 1 ] = guiCreateLabel ( 0.643, 0.0689, 0.3191, 0.0875, "Vehicle Components:", true, g_Window [ 1 ] ) 
	g_Label [ 2 ] = guiCreateLabel ( 0.0307, 0.4262, 0.1206, 0.225, "Rotation\n\nPosition", true, g_Window [ 1 ] ) 
	g_Label [ 3 ] = guiCreateLabel ( 0.2388, 0.423, 0.0567, 0.2333, "X\nY\nZ", true, g_Window [ 1 ] ) 
	g_Label [ 4 ] = guiCreateLabel ( 0.1182, 0.0623, 0.4917, 0.0833, "X            Y            Z", true, g_Window [ 1 ] ) 
	g_Label [ 5 ] = guiCreateLabel ( 0.0307, 0.0984, 0.1206, 0.225, "Rotation\n\nPosition", true, g_Window [ 1 ] ) 
	g_Label [ 6 ] = guiCreateLabel ( 0.0284, 0.3016, 0.2979, 0.15, "Exact offsets (up) \nAdding offsets (down)", true, g_Window [ 1 ] )
	g_Label [ 7 ] = guiCreateLabel ( 0.0200, 0.422, 0.6080, 0.0393, "————————————————————————", true, g_Window [ 1 ] ) 
		
	g_OffsetsEdit.x = guiCreateEdit ( 0.1749, 0.2361, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 
	g_OffsetsEdit.y = guiCreateEdit ( 0.305, 0.2361, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 
	g_OffsetsEdit.z = guiCreateEdit ( 0.435, 0.2393, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 
	g_OffsetsEdit.rx = guiCreateEdit ( 0.1749, 0.1377, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 
	g_OffsetsEdit.ry = guiCreateEdit ( 0.305, 0.1377, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 
	g_OffsetsEdit.rz = guiCreateEdit ( 0.435, 0.1377, 0.1206, 0.0656, "0", true, g_Window [ 1 ] ) 

	g_Edit [ 1 ] = guiCreateEdit ( 0.3877, 0.4754, 0.2317, 0.0689, "0.1", true, g_Window [ 1 ] ) 
		 
	g_Radio [ 1 ] = guiCreateRadioButton ( 0.1655, 0.4721, 0.0355, 0.0459, "", true, g_Window [ 1 ] ) 
	g_Radio [ 2 ] = guiCreateRadioButton ( 0.1655, 0.5672, 0.0378, 0.0426, "", true, g_Window [ 1 ] ) 
	
	g_Grid [ 1 ] = guiCreateGridList ( 0.643, 0.1508, 0.3191, 0.718, true, g_Window [ 1 ] ) 
	 
	-- preparations
	for k, v in ipairs ( g_Window ) do
		guiSetVisible ( v, false )
		guiWindowSetSizable ( v, false )
	end
	
	for k, v in ipairs ( g_Label ) do
		guiLabelSetVerticalAlign ( v, "center" )
		guiLabelSetHorizontalAlign ( v, "center" )
	end
	
	for k, v in pairs ( g_OffsetsEdit ) do
		guiEditSetMaxLength ( v, 5 ) 
	end
	
	guiRadioButtonSetSelected ( g_Radio [ 2 ] , true ) 
	
	guiGridListSetSortingEnabled ( g_Grid [ 1 ], false )
	guiGridListSetSelectionMode ( g_Grid [ 1 ] , 2 ) 
	guiGridListAddColumn ( g_Grid [ 1 ] , "Component Name", 0.8 )
end

-------------------
-- operating GUI --
-------------------

function g_Shower ( bool )
	guiSetVisible ( g_Window [ 1 ], bool )
	showCursor ( bool, false )
end

function g_PreShower () 
	g_Shower ( not guiGetVisible ( g_Window [ 1 ] ) ) 
end

function g_OffsetsEditUpdate ()
	for k, v in pairs ( g_OffsetsEdit ) do
		local number = math.round ( commaToDot ( guiGetText ( v ) ) ) or 0
		posrot [ k ] = number
		guiSetText ( v, tostring ( number ) )
	end
end

function g_DiffUpdate ( element )
	local rotbool = guiRadioButtonGetSelected ( g_Radio [ 1 ] )
	if rotbool then
		rot = commaToDot ( guiGetText ( element ) ) or 15
	else
		pos = commaToDot ( guiGetText ( element ) ) or 0.1
	end
end

function g_ClickHandler ()
	if source == g_Grid [ 1 ] then -- choose theComponent
		local row, column = guiGridListGetSelectedItem ( g_Grid [ 1 ] )
		if row >= 0 then
			theComponent = guiGridListGetItemText ( g_Grid [ 1 ], row, 1 )
			local x, y, z = getVehicleComponentPosition ( theVehicle, theComponent )
			local rx, ry, rz = getVehicleComponentRotation ( theVehicle, theComponent )
			guiSetText ( g_OffsetsEdit.x, x )
			guiSetText ( g_OffsetsEdit.y, y )
			guiSetText ( g_OffsetsEdit.z, z )
			guiSetText ( g_OffsetsEdit.rx, rx )
			guiSetText ( g_OffsetsEdit.ry, ry )
			guiSetText ( g_OffsetsEdit.rz, rz )
			for k, v in pairs ( g_OffsetsEdit ) do
				guiEditSetCaretIndex ( v, 0 )
			end
			g_OffsetsEditUpdate ()
			-- @ down : dunno if i shall update all this crap. sawmtiemz it may be unnecessary but it will still use some memory
			--[[local showBool = getVehicleComponentVisible ( theVehicle, theComponent )
			local oldData = getElementData ( theVehicle, "VCSM" )
			local newData = {}
			if oldData then
				newData = oldData
			end
			newData [ theComponent ] = { showBool, x, y, z, rx, ry, rz }
			setElementData ( theVehicle, "VCSM", newData )]]
		else
			theComponent = nil
		end
	elseif source == g_Button [ 1 ] then -- apply changes
		if theComponent then
			g_OffsetsEditUpdate ()
			local showBool = getVehicleComponentVisible ( theVehicle, theComponent )
			local x = posrot.x
			local y = posrot.y
			local z = posrot.z
			local rx = posrot.rx
			local ry = posrot.ry
			local rz = posrot.rz
			local oldData = getElementData ( theVehicle, "VCSM" )
			local newData = {}
			if oldData then
				newData = oldData
			end
			newData [ theComponent ] = { showBool, x, y, z, rx, ry, rz }
			setElementData ( theVehicle, "VCSM", newData )
		else
			announce ( "noComp" )
		end
	elseif source == g_Button [ 2 ] then -- add
		g_AddOffsets ( 1 )
	elseif source == g_Button [ 3 ] then -- substract
		g_AddOffsets ( -1 )
	elseif source == g_Button [ 4 ] then -- show/hide GUI
		g_Shower ( not guiGetVisible ( g_Window [ 1 ] ) )
	elseif source == g_Button [ 5 ] then -- refresh grid
		theComponent = nil
		for k, v in pairs ( g_OffsetsEdit ) do
			guiSetText ( v, 0 )
			guiEditSetCaretIndex ( v, 0 )
		end
		g_OffsetsEditUpdate ()
		g_GridUpdate ()
		if not theVehicle then
			announce ( "noVeh" )
		end
	elseif source == g_Button [ 6 ] then -- reset all
		if theVehicle then
			local components = getVehicleComponents ( theVehicle )
			local newData = {}
			for component, v in pairs ( components ) do
				resetVehicleComponentPosition ( theVehicle, component )
				resetVehicleComponentRotation ( theVehicle, component )
				local x, y, z = getVehicleComponentPosition ( theVehicle, component )
				local rx, ry, rz = getVehicleComponentRotation ( theVehicle, component )
				newData [ component ] = { true, x, y, z, rx, ry, rz }
			end
			local bool = setElementData ( theVehicle, "VCSM", newData )
			if bool then
				outputChatBox ( "All components' offsets were #9696ffsuccessfully resetted#6464ff.", 100, 100, 255, true )
			else
				outputChatBox ( "An #9696fferror#6464ff occured when resetting components' offsets.", 100, 100, 255, true )
			end
		else
			announce ( "noVeh" )
		end
	elseif source == g_Button [ 7 ] then -- reset
		if theComponent then
			resetVehicleComponentPosition ( theVehicle, theComponent )
			resetVehicleComponentRotation ( theVehicle, theComponent )
			local x, y, z = getVehicleComponentPosition ( theVehicle, theComponent )
			local rx, ry, rz = getVehicleComponentRotation ( theVehicle, theComponent )
			local oldData = getElementData ( theVehicle, "VCSM" )
			local newData = {}
			if oldData then
				newData = oldData
			end
			newData [ theComponent ] = { true, x, y, z, rx, ry, rz }
			local bool = setElementData ( theVehicle, "VCSM", newData )
			if bool then
				outputChatBox ( "Component's offsets were #9696ffsuccessfully resetted#6464ff.", 100, 100, 255, true )
			else
				outputChatBox ( "An #9696fferror#6464ff occured when resetting component's offsets.", 100, 100, 255, true )
			end
		else
			announce ( "noComp" )
		end
	elseif source == g_Button [ 8 ] then -- visibility all
		if theVehicle then
			local oldData = getElementData ( theVehicle, "VCSM" )
			local newData = {}
			local showBool
			if theComponent then
				showBool = not getVehicleComponentVisible ( theVehicle, theComponent )
			else
				showBool = not getVehicleComponentVisible ( theVehicle, "chassis" )
				--[[if oldData then
					showBool = not getVehicleComponentVisible ( theVehicle, "chassis" )
					debg ( "oldData is present. takin chassis' showbool whic is: " .. tostring ( showBool ) )
				else
					debg ( "oldData isn prezen. takin showBool as fals" )
					showBool = false
				end]]
			end
			if oldData then
				newData = oldData
				for component, v in pairs ( getVehicleComponents ( theVehicle ) ) do
					if v ~= showBool then
						local componentData = oldData [ component ]
						if componentData then
							newData [ component ] [ 1 ] = showBool
						else
							local x, y, z = getVehicleComponentPosition ( theVehicle, component )
							local rx, ry, rz = getVehicleComponentRotation ( theVehicle, component )
							newData [ component ] = { showBool, x, y, z, rx, ry, rz }
						end
					end
				end
			else
				for component, v in pairs ( getVehicleComponents ( theVehicle ) ) do
					local _showBool = getVehicleComponentVisible ( theVehicle, component )
					if _showBool ~= showBool then
						local x, y, z = getVehicleComponentPosition ( theVehicle, component )
						local rx, ry, rz = getVehicleComponentRotation ( theVehicle, component )
						newData [ component ] = { showBool, x, y, z, rx, ry, rz }
					end
				end
			end
			setElementData ( theVehicle, "VCSM", newData )
			local r, g, b = unpack ( showBoolToColor [ showBool ] )
			for i = 0, guiGridListGetRowCount ( g_Grid [ 1 ] ) do
				guiGridListSetItemColor ( g_Grid [ 1 ], i, 1, r, g, b )
			end
		else
			announce ( "noVeh" )
		end
	elseif source == g_Button [ 9 ] then -- visibility
		if theComponent then
			local oldData = getElementData ( theVehicle, "VCSM" )
			local newData = {}
			local showBool
			if oldData then
				newData = oldData
				local componentData = oldData [ theComponent ]
				if componentData then
					showBool = not componentData [ 1 ]
					newData [ theComponent ] [ 1 ] = showBool
				else
					showBool = false
					local x, y, z = getVehicleComponentPosition ( theVehicle, theComponent )
					local rx, ry, rz = getVehicleComponentRotation ( theVehicle, theComponent )
					newData [ theComponent ] = { false, x, y, z, rx, ry, rz }
				end
			else
				showBool = false
				local x, y, z = getVehicleComponentPosition ( theVehicle, theComponent )
				local rx, ry, rz = getVehicleComponentRotation ( theVehicle, theComponent )
				newData [ theComponent ] = { false, x, y, z, rx, ry, rz }
			end
			setElementData ( theVehicle, "VCSM", newData )
			local row, column = guiGridListGetSelectedItem ( g_Grid [ 1 ] )
			local r, g, b = unpack ( showBoolToColor [ showBool ] )
			guiGridListSetItemColor ( g_Grid [ 1 ], row, column, r, g, b )
		else
			announce ( "noComp" )
		end
	elseif source == g_Radio [ 1 ] then -- rot diff
		guiSetText ( g_Edit [ 1 ], rot )
	elseif source == g_Radio [ 2 ] then -- pos diff
		guiSetText ( g_Edit [ 1 ], pos )
	end
end

function g_AddOffsets ( multiplier )
	if theComponent then
		local pos = boolToFactor [ guiRadioButtonGetSelected ( g_Radio [ 2 ] ) ]
		local rot = boolToFactor [ guiRadioButtonGetSelected ( g_Radio [ 1 ] ) ]
		if pos or rot then
			local diff = {}
			diff.n = commaToDot ( guiGetText ( g_Edit [ 1 ] ) )
			if not diff.n then
				if posbool then
					diff.n = 0.1
				else
					diff.n = 15
				end
				guiSetText ( g_Edit [ 2 ], diff.n )
			end
			g_OffsetsEditUpdate ()
			local bool = false
			for k, v in pairs ( g_Checkbox ) do
				if guiCheckBoxGetSelected ( v ) then
					diff [ k ] = 1
					bool = true
				else
					diff [ k ] = 0
				end
			end
			if bool then
				local x, y, z = getVehicleComponentPosition ( theVehicle, theComponent )
				local rx, ry, rz = getVehicleComponentRotation ( theVehicle, theComponent )
				local showBool = getVehicleComponentVisible ( theVehicle, theComponent )
				local nx = x + multiplier * diff.n * diff.x * pos
				local ny = y + multiplier * diff.n * diff.y * pos
				local nz = z + multiplier * diff.n * diff.z * pos
				local nrx = rx + multiplier * diff.n * diff.x * rot
				local nry = ry + multiplier * diff.n * diff.y * rot
				local nrz = rz + multiplier * diff.n * diff.z * rot
				guiSetText ( g_OffsetsEdit.x, nx )
				guiSetText ( g_OffsetsEdit.y, ny )
				guiSetText ( g_OffsetsEdit.z, nz )
				guiSetText ( g_OffsetsEdit.rx, nrx )
				guiSetText ( g_OffsetsEdit.ry, nry )
				guiSetText ( g_OffsetsEdit.rz, nrz )
				local oldData = getElementData ( theVehicle, "VCSM" )
				local newData = {}
				if oldData then
					newData = oldData
					if oldData [ theComponent ] then
						newData [ theComponent ] [ 2 ] = nx
						newData [ theComponent ] [ 3 ] = ny
						newData [ theComponent ] [ 4 ] = nz
						newData [ theComponent ] [ 5 ] = nrx
						newData [ theComponent ] [ 6 ] = nry
						newData [ theComponent ] [ 7 ] = nrz
					else
						newData [ theComponent ] = { showBool, nx, ny, nz, nrx, nry, nrz }
					end
				else
					newData [ theComponent ] = { showBool, nx, ny, nz, nrx, nry, nrz }
				end
				setElementData ( theVehicle, "VCSM", newData )
				--[[if posbool then
					local nx = x + multiplier * diff.n * diff.x
					local ny = y + multiplier * diff.n * diff.y
					local nz = z + multiplier * diff.n * diff.z
					guiSetText ( g_OffsetsEdit.x, nx )
					guiSetText ( g_OffsetsEdit.y, ny )
					guiSetText ( g_OffsetsEdit.z, nz )
					local oldData = getElementData ( theVehicle, "VCSM" )
					local newData = {}
					if oldData then
						newData = oldData
						if oldData [ theComponent ] then
							newData [ theComponent ] [ 2 ] = nx
							newData [ theComponent ] [ 3 ] = ny
							newData [ theComponent ] [ 4 ] = nz
						else
							newData [ theComponent ] = { showBool, nx, ny, nz, rx, ry, rz }
						end
					else
						newData [ theComponent ] = { showBool, nx, ny, nz, rx, ry, rz }
					end
					setElementData ( theVehicle, "VCSM", newData )
				else rotbool then
					local nrx = rx + multiplier * diff.n * diff.x
					local nry = ry + multiplier * diff.n * diff.y
					local nrz = rz + multiplier * diff.n * diff.z
					guiSetText ( g_OffsetsEdit.rx, nrx )
					guiSetText ( g_OffsetsEdit.ry, nry )
					guiSetText ( g_OffsetsEdit.rz, nrz )
					local oldData = getElementData ( theVehicle, "VCSM" )
					local newData = {}
					if oldData then
						newData = oldData
						if oldData [ theComponent ] then
							newData [ theComponent ] [ 5 ] = nrx
							newData [ theComponent ] [ 6 ] = nry
							newData [ theComponent ] [ 7 ] = nrz
						else
							newData [ theComponent ] = { showBool, x, y, z, nrx, nry, nrz }
						end
					else
						newData [ theComponent ] = { showBool, x, y, z, nrx, nry, nrz }
					end
					setElementData ( theVehicle, "VCSM", newData )
				end]]
				g_OffsetsEditUpdate ()
			else
				outputChatBox ( "You must select at least one of #9696ffX#6464ff, #9696ffY#6464ff or #9696ffZ#6464ff axes!", 100, 100, 255, true )
			end
		else
			outputChatBox ( "You must select #9696ffPosition#6464ff or #9696ffRotation#6464ff change!", 100, 100, 255, true )
		end
	else
		announce ( "noComp" )
	end
end

function g_GridClean ()
	guiGridListClear ( g_Grid [ 1 ] )
	theComponent = nil
	for k, v in pairs ( g_OffsetsEdit ) do
		guiSetText ( v, 0 )
		guiEditSetCaretIndex ( v, 0 )
	end
end

function g_GridUpdate ()
	g_GridClean ()
	if theVehicle and guiGetVisible ( g_Window [ 1 ] ) then
		local components = getVehicleComponents ( theVehicle )
		for component, v in pairs ( components ) do
			local row = guiGridListAddRow ( g_Grid [ 1 ] )
			guiGridListSetItemText ( g_Grid [ 1 ], row, 1, component, false, false )
			local r, g, b = unpack ( showBoolToColor [ getVehicleComponentVisible ( theVehicle, component ) ] )
			guiGridListSetItemColor ( g_Grid [ 1 ], row, 1, r, g, b )
		end
	end
end

-------------
-- updates --
-------------

function getDistanceBetweenElements ( element1, element2 )
	if isElement ( element1 ) and isElement ( element2 ) then
		local x1, y1, z1 = getElementPosition ( element1 )
		local x2, y2, z2 = getElementPosition ( element2 )
		return getDistanceBetweenPoints3D ( x1, y1, z1, x2, y2, z2 )
	end
	return false
end

function VCSMupdate ( vehicle )
	local data = getElementData ( vehicle, "VCSM" )
	if data then
		for component, v in pairs ( data ) do
			local showBool, x, y, z, rx, ry, rz = unpack ( v )
			--if getVehicleComponentVisible ( vehicle, component ) ~= showBool or getVehicleComponentPosition ( vehicle, component ) ~= ( x, y, z ) or getVehicleComponentRotation ( vehicle, component ) ~= ( rx, ry, rz ) then
				setVehicleComponentVisible ( vehicle, component, showBool )
				setVehicleComponentPosition ( vehicle, component, x, y, z )
				setVehicleComponentRotation ( vehicle, component, rx, ry, rz )
			--end
		end
	end
end

function VCSMpreUpdate ()
	for k, v in ipairs ( getElementsByType ( "vehicle" ) ) do
		if getDistanceBetweenElements ( thePlayer, v ) <= 80 then
			VCSMupdate ( v )
		end
	end
end
setTimer ( VCSMpreUpdate, 150, 0 )

function vehicleUpdate ()
	local vehicle = getPedOccupiedVehicle ( thePlayer )
	if theVehicle ~= vehicle then
		theVehicle = vehicle
		g_GridUpdate ()
	end
end
vehicleUpdate ()

--------------
-- handlers --
--------------

addEventHandler ( "onClientGUIChanged", g_Edit [ 1 ], g_DiffUpdate, false )
addEventHandler ( "onClientPlayerVehicleEnter", thePlayer, vehicleUpdate, false )
addEventHandler ( "onClientPlayerVehicleExit", thePlayer, vehicleUpdate, false )
addEventHandler ( "onClientPlayerWasted", thePlayer, vehicleUpdate, false )
addEventHandler ( "onClientGUIClick", root, g_ClickHandler )
addCommandHandler ( "vcsm", g_PreShower )
addCommandHandler ( "VCSM", g_PreShower )